package com.wenwei.activity;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.view.View;
import android.widget.AdapterView;
import android.widget.TextView;

import com.flyco.dialog.listener.OnOperItemClickL;
import com.flyco.dialog.widget.ActionSheetDialog;
import com.jcodecraeer.xrecyclerview.XRecyclerView;
import com.orhanobut.logger.Logger;
import com.wenwei.adapter.HistoryPoiAdapter;
import com.wenwei.bean.HisPointBean;
import com.wenwei.net.ApiManager;
import com.wenwei.net.BaseSubscriber;
import com.wenwei.parking.BaseActivity;
import com.wenwei.parking.R;
import com.wenwei.utils.MapUtils;
import com.wenwei.utils.UserStringUtils;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2017/8/22.
 */
public class HistoryPoiActivity extends BaseActivity implements HistoryPoiAdapter.CallBack{
    @Bind(R.id.base_title)
    TextView baseTitle;
    @Bind(R.id.recycler)
    XRecyclerView recycler;

    HistoryPoiAdapter mAdapter;

    @Bind(R.id.empty)
    View mView;
    @Override
    public int setLayoutResourceId() {
        return R.layout.activity_history;
    }

    @Override
    protected void initView() {
        super.initView();
        baseTitle.setText("历史地点");
        mAdapter = new HistoryPoiAdapter();
        mAdapter.setmCallBack(this);
        recycler.setLayoutManager(new LinearLayoutManager(mContext));
        recycler.setEmptyView(mView);
        recycler.setAdapter(mAdapter);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick(R.id.base_back)
    public void onViewClicked() {
        finish();
    }

    @Override
    protected void initData() {
        super.initData();
        getHistoryParkAddr();
    }

    //历史地点
    private BaseSubscriber<ArrayList<HisPointBean>> pointSb;
    private void getHistoryParkAddr(){
        pointSb = new BaseSubscriber<ArrayList<HisPointBean>>(mContext) {
            @Override
            public void onSuccess(ArrayList<HisPointBean> hisPointBeen) {
                mAdapter.setmList(hisPointBeen);
                mAdapter.notifyDataSetChanged();
            }
        };
        ApiManager.getInstance().getHistoryParkAddr(pointSb, UserStringUtils.getUserId(mContext));
    }

    @Override
    public void onItemClick(HisPointBean bean) {
        showDialog(bean);
    }


    private void showDialog(final HisPointBean bean) {
        final ActionSheetDialog dialog = new ActionSheetDialog(mContext, new String[]{"百度地图", "高德地图"}, null);
        dialog.title("选择导航方式");
        dialog.show();
        dialog.setOnOperItemClickL(new OnOperItemClickL() {
            @Override
            public void onOperItemClick(AdapterView<?> parent, View view, int position, long id) {
                Logger.d("当前位置：" + position);
                if(position == 0){
                    MapUtils.goLocation(mContext,"baiDu",Double.parseDouble(bean.getLongitude()),Double.parseDouble(bean.getLongitude()),bean.getParkAddress());
                }else if (position == 1){
                    MapUtils.goLocation(mContext,"gaoDe",Double.parseDouble(bean.getLongitude()),Double.parseDouble(bean.getLongitude()),bean.getParkAddress());
                }
                dialog.dismiss();
            }
        });
    }
}
